/**
 * Created by dale on 2017/9/6.
 */
$(document).ready(function () {
    var form=new xhForm($('.xh-form'));

    form.parse().bindRequired($('#bt_modal_confirm',parent.document));

    var staffId=addressUri.getParam('staffId');
    var staffName=addressUri.getParam('staffName');
    staffName=unescape(staffName);
    $('[name="staffId"]').val(staffId);
    $('[name="staffName"]').val(staffName);
    $('#cc1').combotree({
        onChange:function(newValue, oldValue){
            var $depArr = $(this).combotree('getValues');
            $.ajax({
                url:moduleUrl+'staff/getCharge',
                data:{depArr:$depArr},
                type:'POST',
                dataType:'json',
                success:function (data) {
                    $('#depChargeInfo').empty().append('<font color="red">'+data['msg']+'</font>');
                },
                error:function (data) {
                    console.log(data);
                }
            });
        }
    });
    if(chargeDep){
        $('#cc1').combotree('setValues', chargeDep['chargeDep']);
        // $('#cc1').combotree('combo')('panelHeight',150);
    }


    $('#bt_modal_confirm',parent.document).click(function () {
        var sChargeDeps=$('#cc1').combotree('getValues');
        // console.log(sChargeDeps);
        $('#bt_modal_confirm',parent.document).addClass('disabled');
        $.ajax({
            url:moduleUrl+'staff/saveCharge',
            data:{id:staffId,sChargeDeps:sChargeDeps},
            type:'POST',
            success:function (data) {
                window.top.xhTop.getActiveFrame().staffList.dataGridReload();
                window.top.xhTop.closeModal();
            },
            error:function (data) {
                console.log(data);
            }
        });
    });

    modalBind.bindClick();
});
